﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using STKMIS.DAL;
using STKMIS.Model;
using System.Data;

namespace STKMIS.BLL
{
    public class ProductsAndUnit
    {
        public ProductsAndUnit() { }

        /// <summary>
        /// 插入产品采购明细相关数量
        /// </summary>
        /// <param name="productAndUnitInfo"></param>
        /// <param name="tran"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static bool InsertProductsAndUnit(ProductsAndUnitModel productAndUnitInfo, DBTransaction tran, ref string msg)
        {
            int executedRows = 0;
            bool isTrue = true;
            try
            {

                List<SqlDBParameter> param = new List<SqlDBParameter>();

                param.Add(new SqlDBParameter("@PurchaseItemID", DbType.Int32, productAndUnitInfo.PurchaseItemID));
                param.Add(new SqlDBParameter("@ProductID", DbType.Int32, productAndUnitInfo.ProductID));
                param.Add(new SqlDBParameter("@ProductUnitID", DbType.Int32, productAndUnitInfo.ProductUnitID));
                param.Add(new SqlDBParameter("@ProductSumAmount", DbType.Decimal, productAndUnitInfo.ProductSumAmount));
                param.Add(new SqlDBParameter("@ProductNowAmount", DbType.Decimal, productAndUnitInfo.ProductNowAmount));
                param.Add(new SqlDBParameter("@PurchasePrice", DbType.Decimal, productAndUnitInfo.PurchasePrice));  

                param.Add(new SqlDBParameter("@Msg", DbType.String, ParameterDirection.Output, 50));


                executedRows = SqlDBServer.ExecuteStoredProc("proc_ProductsAndUnitInsert", param, tran.Transaction, SqlDBServer.SqlConnStringModelDb);

                if (executedRows <= 0)
                {
                    isTrue = false;
                }
                else
                {
                    
                    if (param[6].Value != null)
                    {
                        msg = param[6].Value.ToString();
                    }
                    else
                    {
                        isTrue = false;
                    }
                }

                return isTrue;
            }
            catch
            {
                return false;
            }
        }
    }
}
